package com.cat.dataStructure;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/number-of-sub-arrays-with-odd-sum/
 * @create 2025/8/16 11:14
 * @since JDK17
 */

public class Solution25 {
    static int N = ((int) (1e9 + 7));
    public int numOfSubarrays(int[] arr) {
        int n = arr.length, ans = 0, odd = 0, sum = 0;
        for (int i = 0; i < n; i++) {
            sum += arr[i];
            if ((sum & 1) == 0) {  // 奇数
                ans = (ans + i + 1 - odd) % N;
                odd++;
            } else {    // 偶数
                ans = (ans + odd) & N;
            }
        }
        return ans;
    }
}
